<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
    /* 
    * 编写函数maxr(char) 返回字符串char中最长的连续重复字母
    * 比如maxr("mmmiijjjjkkkkkkssptr") 返回"kkkkkk"
    */

    //定义函数
    function maxr(char){
      //初始化变量
      var preChar = char.charAt('0'), curChar = preChar;
      var preLength = 0, curLength = 0;
      for(var i = 0; i<char.length; i++){
        // debugger
        var myChar = char.charAt(i);
        if(myChar == curChar){
          curLength += 1;
        }else{
          //如果当前串发生变化，比较大小，记录最大值
          if(curLength > preLength){
            preChar = curChar;
            preLength = curLength
          }
          //当前长度置1
          curChar = char.charAt(i);
          curLength = 1;
        }
      }
      var length = Math.max(curLength, preLength);
      var getChar = length == curLength ? curLength : preChar;
      var str = ''
      for(var i = 0; i <= length; i++){
        str += getChar;
      }
      return str;
    }

    console.log(maxr('mmmiijjjjkkkkkkssptr')) // kkkkkk

</script>
</html>